from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework_extensions.cache.mixins import RetrieveCacheResponseMixin, ListCacheResponseMixin

from areas.models import Area
from areas.serializers import AreaSerializer, SubAreaSerializer


# 查询所有省份
# class AreaProvinceView(ListAPIView):

# 为省市区视图添加缓存
class AreaProvinceView(ListCacheResponseMixin, ListAPIView):
    # 查询所有省份
    queryset = Area.objects.filter(parent=None)
    serializer_class = AreaSerializer

    # 用分页禁功能
    pagination_class = None


# 查询省份下面的城市和区县
class SubAreaView(RetrieveCacheResponseMixin, RetrieveAPIView):
    queryset = Area.objects.all()   # # 查询一个区域（城市和区县）
    serializer_class = SubAreaSerializer

# class AddressViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, GenericViewSet):




